﻿using EMall.IdentityService.Users;
using EMall.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace EMall.IdentityService.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class UserController : ControllerBase
    {
        private readonly IUserAppService _userAppService;
        public UserController(IUserAppService userAppService)
        {
            _userAppService = userAppService;
        }
        [HttpPost]
        public async Task CreateAsync(CreateUserDto input)
        {
            await _userAppService.CreateAsync(input);
        }
        [HttpPut]
        public async Task UpdateAsync(UpdateUserDto input)
        {
            await _userAppService.UpdateAsync(input);
        }
        [HttpDelete]
        public async Task DeleteAsync(DeleteUserDto input)
        {
            await _userAppService.DeleteAsync(input);
        }
        [HttpGet]
        public async Task<UserDto> GetAsync(int id)
        {
            return await _userAppService.GetAsync(id);
        }
        [HttpGet]
        public async Task<IEnumerable<UserListDto>> GetListAsync([FromQuery] GetUserListQueryDto input)
        {
            return await _userAppService.GetListAsync(input);
        }
        [HttpGet]
        public async Task<IPagedList<UserListDto>> GetPagedListAsync([FromQuery] GetUserListPagingAndSortingQueryDto input)
        {
            return await _userAppService.GetPagedListAsync(input);
        }
    }
}
